home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C++ / Applications / PICSee Dust 1.01 / Secondary Source / PICS_Utils.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-13  |  2.8 KB  |  131 lines  |  [TEXT/CWIE]

  1. #include "PICS_Utils.h"
  2. #include "PICS_Types.h"
  3.  
  4. #include "PICS_Operations.h"    // For error-codes
  5. #include "SimpleError.h"
  6. #include "assert_mac.h"
  7.  
  8. #include <ImageCompression.h>    // For StandardGetFilePreview()
  9. #include <PictUtils.h>            // For GetPictInfo()
  10. #include <Gestalt.h>
  11.  
  12. // ---------------------------------------------------------------------------
  13.  
  14. Boolean OpenPICSFile(FSSpec *file) {
  15.     StandardFileReply reply;
  16.     SFTypeList typeList;
  17.     long info;
  18.     Boolean hasPreview;
  19.  
  20.     ASSERT(file != NULL);
  21.  
  22.     Gestalt(gestaltQuickTime, &info);
  23.     if (info > 0)
  24.         hasPreview = true;
  25.     else
  26.         hasPreview = false;
  27.  
  28.     typeList[0] = kPICSFileType1;
  29.     typeList[1] = kPICSFileType2;
  30.  
  31.     if (hasPreview)
  32.         StandardGetFilePreview(NULL, 2, typeList, &reply);
  33.     else
  34.         StandardGetFile(NULL, 2, typeList, &reply);
  35.  
  36.     if (reply.sfGood) {
  37.         *file = reply.sfFile;
  38.         return(true);
  39.     }
  40.     else
  41.         return(false);
  42. } // END OpenPICSFile
  43.  
  44. // ---------------------------------------------------------------------------
  45.  
  46. Boolean OpenPICTFile(FSSpec *file) {
  47.     StandardFileReply reply;
  48.     SFTypeList typeList;
  49.     long info;
  50.     Boolean hasPreview;
  51.  
  52.     Gestalt(gestaltQuickTime, &info);
  53.     if (info > 0)
  54.         hasPreview = true;
  55.     else
  56.         hasPreview = false;
  57.  
  58.     ASSERT(file != NULL);
  59.  
  60.     typeList[0] = kPICTFileType;
  61.  
  62.     if (hasPreview)
  63.         StandardGetFilePreview(NULL, 1, typeList, &reply);
  64.     else
  65.         StandardGetFile(NULL, 1, typeList, &reply);
  66.  
  67.     if (reply.sfGood) {
  68.         *file = reply.sfFile;
  69.         return(true);
  70.     }
  71.     else
  72.         return(false);
  73. } // END OpenPICTFile
  74.  
  75. // ===========================================================================
  76.  
  77. Boolean FetchPICSFileInfo(
  78.     const FSSpec    *file,            // Input
  79.     Rect            *picsRect,        // Output
  80.     short            *picsDepth,        // Output
  81.     short            *numFrames) {    // Output
  82.  
  83.     short        fileRefNum;
  84.     short        numOfFrames;
  85.     PicHandle    thePic;
  86.  
  87.     fileRefNum = FSpOpenResFile(file, fsRdWrPerm);
  88.     if (fileRefNum == -1) {
  89.         SimpleError(kAlertErrID, kErrMsgID, kCantOpenFileErrMsg);
  90.         return(false);
  91.     }
  92.     UseResFile(fileRefNum);
  93.     
  94.     numOfFrames = Count1Resources(kPICSRsrcType);
  95.     if (numOfFrames < 1) {
  96.         SimpleError(kAlertErrID, kErrMsgID, kNoPICTsInFileErrMsg);
  97.         return(false);
  98.     }
  99.     *numFrames = numOfFrames;
  100.  
  101.     thePic = (PicHandle)Get1Resource(kPICSRsrcType, kPICSRsrcStartID);
  102.     if (thePic == NULL) {
  103.         SimpleError(kAlertErrID, kErrMsgID, kInvalidPICSFormatErrMsg);
  104.         return(false);
  105.     }
  106.  
  107.     *picsRect = (**thePic).picFrame;
  108.     *picsDepth = GetPictDepth(thePic);
  109.  
  110.     ReleaseResource((Handle)thePic);
  111.     CloseResFile(fileRefNum);
  112.     return(true);
  113. } // END FetchPICSFileInfo
  114.  
  115. // ---------------------------------------------------------------------------
  116.  
  117. short GetPictDepth(PicHandle thePic) {
  118.     PictInfo    pictInfo;
  119.     OSErr        myErr;
  120.  
  121.     myErr = GetPictInfo(thePic, &pictInfo, returnPalette,
  122.         1, systemMethod, 0);
  123.  
  124.     if (myErr == noErr) {
  125.         return(pictInfo.depth);
  126.     }
  127.     else {
  128.         SimpleError(kAlertErrID, kErrMsgID, kCantGetPictInfoErrMsg);
  129.         return(0);
  130.     }
  131. } // END GetPictDepth